import 'package:flutter/material.dart';
import 'package:xindong/common/xindong_sezhi.dart';
import 'package:xindong/common/xindong_types.dart';
import 'package:xindong/res/assets_res.dart';
import 'package:xindong/routes/call/model/xindong_signal_class.dart';
import 'package:xindong/utils/xindong_calender_util.dart';
import 'package:xindong/utils/xindong_image_util.dart';
import 'package:tencent_cloud_chat_uikit/tencent_cloud_chat_uikit.dart';

class XinDongLiaoTianMessageCalling extends StatelessWidget {
  final V2TimMessage message;
  final XinDongSignalClass model;
  final int type;
  final double maxWidth;

  const XinDongLiaoTianMessageCalling(
      {Key? key, required this.message, required this.model, required this.type, required this.maxWidth})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    if (model.status == 1) {
      return const SizedBox();
    }
    final isFromSelf = message.isSelf == true;
    final backgroundColor = isFromSelf ? Colors.grey.shade300 : Colors.white;
    String text = "";
    String imageName = type == ChatType.callAudio ? AssetsRes.CALL_TIME_AUDIO : AssetsRes.CALL_TIME_VIDEO;
    if (model.start != null && model.end != null && model.start !=  model.end) {
      text = " 通话时长 ${XinDongCalendarUtil.timeTextHMS(model.end! - model.start!)}";
    } else {
      text = " [${type == ChatType.callAudio ? "语音" : "视频"}通话]未接通";
    }
    print(text);
    print(model.toJson());
    return Container(
      padding: const EdgeInsets.all(10),
      decoration: BoxDecoration(color: backgroundColor, borderRadius: BorderRadius.circular(10)),
      constraints: BoxConstraints(minWidth: 40, maxWidth: maxWidth),
      child: Text.rich(
        TextSpan(children: [
          WidgetSpan(child: ImageUtil.asset(imageName, width: 24, height: 24)),
          TextSpan(text: text),
        ]),
        textAlign: text.trim().length < 5 ? TextAlign.center : TextAlign.left,
        softWrap: true,
        style: const TextStyle(fontSize: 16, height: 1.2, color: DZColors.titleColor),
      ),
    );
  }
}
